// 页面渲染
var id = $.getUrlParam('id');

//$.ajax({
//    type: "GET",
//	url: "/event/updatetmp",
//	data:{'id':id},
//	dataType: "json",
//	success: function (result) {
//	       	if(result.status){
//
//				var data = result.data
//
//                $('#activityTmpId').val(data.id);
//				$('#title').val(data.title);
//
//				$('#cover_path').val(data.cover_path);
//                $("#cover_path_src").attr('src',data.cover_path_src);
//
//                $('#description').html(data.description);
//
//				$('#create_time').val(data.create_time);
//
//				$('#end_time').val(data.end_time)
//
//				$('#address').val(data.address);
//
//                var publicSelects = data.publicSelect;
//                $.each(publicSelects, function(index, publicSelect) {
//                    if(data.is_public == publicSelect.id){
//                        $("#is_public").append('<option value="' + publicSelect.id + '" selected = "selected">' + publicSelect.name + '</option>');
//                    }else{
//                        $("#is_public").append('<option value="' + publicSelect.id + '">' + publicSelect.name + '</option>');
//                    }
//                });
//                var freeSelects = data.freeSelect;
//                $.each(freeSelects, function(index, freeSelect) {
//                    if(data.is_free == freeSelect.id){
//                        $("#is_free").append('<option value="' + freeSelect.id + '" selected = "selected">' + freeSelect.name + '</option>');
//                    }else{
//                        $("#is_free").append('<option value="' + freeSelect.id + '">' + freeSelect.name + '</option>');
//                    }
//                });
//                var statusSelects = data.statusSelect;
//                $.each(statusSelects, function(index, statusSelect) {
//                    if(data.status == statusSelect.id){
//                        $("#status").append('<option value="' + statusSelect.id + '" selected = "selected">' + statusSelect.name + '</option>');
//                    }else{
//                        $("#status").append('<option value="' + statusSelect.id + '">' + statusSelect.name + '</option>');
//                    }
//                });
//                //收费活动的票子信息
//                if('' != data.ticket){
//                    $('#ticket').show();
//                    var eventTickets = data.ticket;
//                    var currencySelects = data.currencySelect;
//                    $.each(eventTickets, function(index, eventTicket){
//                        //1会员0非会员,2早鸟会员价,3早鸟非会员价
//                        if(1 == eventTicket.is_member){
//                            $('#ticket_mb_title').val(eventTicket.title);
//                            $('#ticket_mb_price').val(eventTicket.price);
//                            $('#ticket_mb_count').val(eventTicket.count);
//                            $("#ticket_mb_currency").html('');
//                            $.each(currencySelects, function(index, currencySelect) {
//                                if(eventTicket.currency == currencySelect.id){
//                                    $("#ticket_mb_currency").append('<option value="' + currencySelect.id + '" selected = "selected">' + currencySelect.name + '</option>');
//                                }else{
//                                    $("#ticket_mb_currency").append('<option value="' + currencySelect.id + '">' + currencySelect.name + '</option>');
//                                }
//                            });
//                        }else if(0 == eventTicket.is_member){
//                            $('#ticket_mb_f_title').val(eventTicket.title);
//                            $('#ticket_mb_f_price').val(eventTicket.price);
//                            $('#ticket_mb_f_count').val(eventTicket.count);
//                            $("#ticket_mb_f_currency").html('');
//                            $.each(currencySelects, function(index, currencySelect) {
//                                if(eventTicket.currency == currencySelect.id){
//                                    $("#ticket_mb_f_currency").append('<option value="' + currencySelect.id + '" selected = "selected">' + currencySelect.name + '</option>');
//                                }else{
//                                    $("#ticket_mb_f_currency").append('<option value="' + currencySelect.id + '">' + currencySelect.name + '</option>');
//                                }
//                            });
//                        }else if(2 == eventTicket.is_member){
//                            $('#ticket_eb_title').val(eventTicket.title);
//                            $('#ticket_eb_price').val(eventTicket.price);
//                            $('#ticket_eb_count').val(eventTicket.count);
//                            $("#ticket_eb_currency").html('');
//                            if(eventTicket.early_bird_deadline != 0){
//                                $('#early_bird_deadline').val(eventTicket.early_bird_deadline);
//                            }
//                            $.each(currencySelects, function(index, currencySelect) {
//                                if(eventTicket.currency == currencySelect.id){
//                                    $("#ticket_eb_currency").append('<option value="' + currencySelect.id + '" selected = "selected">' + currencySelect.name + '</option>');
//                                }else{
//                                    $("#ticket_eb_currency").append('<option value="' + currencySelect.id + '">' + currencySelect.name + '</option>');
//                                }
//                            });
//                        }else if(3 == eventTicket.is_member){
//                            $('#ticket_eb_f_title').val(eventTicket.title);
//                            $('#ticket_eb_f_price').val(eventTicket.price);
//                            $('#ticket_eb_f_count').val(eventTicket.count);
//                            $("#ticket_eb_f_currency").html('');
//                            if(eventTicket.early_bird_deadline != 0){
//                                $('#early_bird_deadline').val(eventTicket.early_bird_deadline);
//                            }
//                            $.each(currencySelects, function(index, currencySelect) {
//                                if(eventTicket.currency == currencySelect.id){
//                                    $("#ticket_eb_f_currency").append('<option value="' + currencySelect.id + '" selected = "selected">' + currencySelect.name + '</option>');
//                                }else{
//                                    $("#ticket_eb_f_currency").append('<option value="' + currencySelect.id + '">' + currencySelect.name + '</option>');
//                                }
//                            });
//                        }
//                    });
//                }
//                //是否为管理员打开的详情页
//                if(data.isAdmin){
//                    buttonHtml = '<button type="submit" class="btn btn-default btn-pad" id="adminSubmit"> 确认发布 </button>';
//                    buttonHtml += '<button type="submit" class="btn btn-default btn-pad" id="adminReturn"> 退回 </button>';
//                    $('#adminButton').html(buttonHtml);
//                }
//			}else{
//                $.successAlert(result.msg);
//
//                setTimeout(function (){window.location.href='/event/tmp'}, 3000)
//            }
//	},
//	error: function (XMLHttpRequest, textStatus, errorThrown) {
//	        alert(errorThrown);
//	},
//	async: false
//});



$('#submit').click(function(){

	var data = $('#from').serialize();

	data = data+'&id='+id;
	// console.log($('#from').serialize());return;
	var btn = $(this).button('loading')

	$.post("/event/updatetmp",
			data,
			function(result){
	            if(result.status == true){
	              	
					$.successAlert(result.msg);

					setTimeout(function (){window.location.href='/event/tmp'}, 3000)
	            }else{
	            	$.errorAlert(result.msg);
	            	
					btn.button('reset')

					return false;	
	            }
	},"json");

});

$('#adminSubmit').click(function(){
    var activityTmpId = $('#activityTmpId').val();
    $.post("/event/release",
        { id:activityTmpId },
        function(result){
            if(result.status == true){

                $.successAlert(result.msg);

                setTimeout(function (){window.location.href='/event'}, 3000)
            }else{
                $.errorAlert(result.msg);

                btn.button('reset')

                return false;
            }
        },"json");
});

//function unixToDate(datetime) {
//    var timestamp = datetime;
//    var newDate = new Date();
//    newDate.setTime(timestamp * 1000);
//    var   year=newDate.getFullYear();
//    var   month=newDate.getMonth()+1;
//    var   date=newDate.getDate();
//    var   hour=newDate.getHours();
//    var   minute=newDate.getMinutes();
//    var   second=newDate.getSeconds();
//    return   year+"-"+month+"-"+date+"   "+hour+":"+minute+":"+second;
//}